package command

import (
	"fmt"
	"github.com/spf13/cobra"
	"go-demo-2025/service/users"
	"os"
	"time"
)

// go run script/command.go userCmd --operate exportData
func init() {
	RootCmd.AddCommand(userCmd)
}

var userCmd = &cobra.Command{
	Use:   "userCmd",
	Short: "关于用户相关的命令行操作",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("--- userCmd 运行 ---")
		userCmdRun(args)
	},
}

func userCmdRun(args []string) {
	if operate == "" {
		fmt.Println("缺少参数operate")
		os.Exit(1)
	}

	if operate == "createMockData" { //生成mock数据
		fmt.Println("执行createMockData...")
		service := users.NewUserService()
		service.BatchCreateMockData()
	} else if operate == "exportData" { //导出用户数据
		fmt.Println("执行exportData...")
		service := users.NewUserService()

		startTime := time.Now()
		service.ExportUserList()
		endTime := time.Now()
		timeCost := endTime.Sub(startTime)
		fmt.Println("总耗时: ", timeCost)
	} else {
		fmt.Println("暂未定义此operate的业务逻辑")
		os.Exit(1)
	}
}
